<template>
    <div>
        <el-dialog
            title="修改种子"
            :visible.sync="dialogVisible"
            width="880px"
        >
            <el-form ref="form" :model="form" label-width="120px" size="small">
                <el-form-item label="种子名称:" prop="name"
                              :rules="[{required: true, message: '请输入种子名称', trigger: 'blur'}]">
                    <el-input :autofocus="true" v-model="form.name" placeholder="请输入种子名称"></el-input>
                </el-form-item>
                <el-form-item label="适合地质:" prop="name">
                    <el-input :autofocus="true" v-model="form.geology" placeholder="请输入适合地质"></el-input>
                </el-form-item>
                <el-form-item label="发芽条件:" prop="name">
                    <el-input :autofocus="true" v-model="form.germinate" placeholder="请输入发芽条件"></el-input>
                </el-form-item>
                <el-form-item label="周期:" prop="name">
                    <el-input :autofocus="true" v-model="form.liveSpan" placeholder="请输入周期">
                        <template slot="append">天</template>
                    </el-input>
                </el-form-item>
                <el-form-item label="经济价值:" prop="name">
                    <el-input :autofocus="true" v-model="form.economic" placeholder="请输入经济价值"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancel" size="small">取 消</el-button>
                <el-button type="primary" @click="onSubmit" size="small">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import {mapState} from "vuex";
import {upDateSeed} from "@/index/api/index/adoption/adoptionManage/seed/index"

export default {
    data() {
        return {
            dialogVisible: false,
            form: {
                name: "",
                geology: "",
                germinate: "",
                liveSpan: "",
                economic: "",
            },
        }
    },
    computed: {
        ...mapState(["token"]),
    },
    methods: {
        cancel() {
            this.dialogVisible = false;
            this.$refs["form"].resetFields();
        },
        showDialog(e, row) {
            this.form = row
            this.dialogVisible = !this.dialogVisible
        },
        onSubmit() {
            this.form.liveSpan = parseInt(this.form.liveSpan)
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    upDateSeed(this.form, this.form.id).then(res => {
                        if (res.code == 200) {
                            this.dialogVisible = false;
                            this.$message({
                                message: res.message,
                                type: "success",
                            });
                            this.$parent.getFarmList();
                            this.$refs["form"].resetFields();
                        } else {
                            this.$message({
                                message: res.message,
                                type: "error",
                            });
                        }
                    })
                } else {
                    this.$message.warning('请输入正确的信息')
                }

            });

        },

    }
}
</script>

<style lang="less" scoped>

.flex-container {
    display: flex;
    align-items: center; /* 垂直居中 */
    margin-top: 10px;
}
</style>
